import java.util.*;

/**
 * @author LKQ
 * @date 2022/4/21 14:42
 * @description floyd算法
 */
public class Solution {
    public static void main(String[] args) {

    }

    public List<Boolean> checkIfPrerequisite(int numCourses, int[][] prerequisites, int[][] queries) {
        boolean[][] graph = new boolean[numCourses][numCourses];
        for (int[] p: prerequisites) {
            // 代表 a -> b 可达
            graph[p[0]][p[1]] = true;
        }
        // floyd算法
        for (int k = 0; k < numCourses; k++) {
            for (int i = 0; i < numCourses; i++) {
                for (int j = 0; j < numCourses; j++) {
                    if (graph[i][k] && graph[k][j]) {
                        graph[i][j] = true;
                    }
                }
            }
        }
        List<Boolean> ans = new ArrayList<>();
        for (int[] q : queries) {
            ans.add(graph[q[0]][q[1]]);
        }
        return ans;
    }


}
